#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

void checkRow(const string &r, int n) {
    if ((int)r.length() != n) {
         quitf(_pe, "Incorrect string length: %d in output, but %d expected", (int)r.length(), n);
    }
    for (char c : r) {
        if (c != '.' && c != '#') {
            quitf(_pe, "Incorrect character with code %d, expected only '.' or '#'", (int)c);
        }
    }
}

int main(int argc, char *argv[]) {
  registerTestlibCmd(argc, argv);
  int n = inf.readInt();
  int k = inf.readInt();
  string jury = upperCase(ans.readLine());
  string stud = upperCase(ouf.readLine());
  if (stud == "NO SOLUTION"){
      if (!ouf.seekEof()) {
          quitf(_pe, "Extra data in output");
      }
      if (stud == jury) {
          quitf(_ok, "Accepted");
      } else {
          quitf(_wa, "Answer exists, but 'No solution' in output");
      }
  }
  checkRow(stud, n);
  vector<string> f(n);
  f[0] = stud;
  for (int i = 1; i < n; i++) {
      f[i] = ouf.readLine();
      checkRow(f[i], n);
  }
  if (!ouf.seekEof()) {
      quitf(_pe, "Extra data in output");
  }
  if (f[0][0] == '#') {
      quitf(_wa, "Path not exists: start cell contains '#'");  
  }
  if (f[n - 1][n - 1] == '#') {
      quitf(_wa, "Path not exists: finish cell contains '#'");  
  }
  vector<vector<int> > p(n, vector<int>(n, -1)); // lengths of paths
  p[0][0] = 1; // count cells, not steps
  queue<pair<int, int> > q;
  q.push({0, 0});
  while (!q.empty()) {
      pair<int, int> u = q.front();
      q.pop();
      for (int di = -1; di <= 1; di++){
           if (u.first + di < 0 || u.first + di >= n)
               continue;
           for (int dj = -1; dj <= 1; dj++) {
               if (u.second + dj < 0 || u.second + dj >= n)
                   continue;
               if (di * di + dj * dj != 1)
                   continue;
               if (f[u.first + di][u.second + dj] != '.')
                   continue;
               if (p[u.first + di][u.second + dj] >= 0)
                   continue;
               p[u.first + di][u.second + dj] = p[u.first][u.second] + 1;
               q.push({u.first + di, u.second + dj});
           }
      }
  }
  if (p[n - 1][n - 1] < 0) {
      quitf(_wa, "Path not exists");    
  }
  if (p[n - 1][n - 1] != k) {
      quitf(_wa, "Wrong path length: expected %d, but detected %d", k, p[n - 1][n - 1]);
  }
  quitf(_ok, "Accepted");
}
